# -*- coding: utf-8 -*-
"""
Created on Fri Aug 29 13:46:33 2014

@author: loseair123


#python的高级功能 不同的权限
f1=file("d:\\test.txt",'r+')
f1.write('Hello Python!')
f1.close()


f2=file("d:\\test.txt",'r+')
print f2.read()
#f2.write('This is f2!')
f2.close()


f3=open("d:\\test.txt",'r+')
print f3.read()
print f3.read()
print f3.read()
print f3.read()
print f3.read()


f3=open("d:\\test.txt",'r+')
for i in f3:
    print i
    

f3=open("d:\\test.txt",'r+')
print f3.readline()
print f3.readlines()

f3=open("d:\\test.txt",'a')
l=['one\n','two\n','three\n','four\n']
f3.writelines(l)
f3.flush()


f3=open("d:\\test.txt",'r+')
print f3.read()
f3.seek(0,0)
f3.write('hi~')
f3.close()



#文件的查找个替换

import re
count=0
f1=open("d:\\test.txt",'r+')
for s in f1.readlines():
    li=re.findall('is',s)
    if len(li)>0:
        count+=1

print 'totally there are ',count,'in file'
"""
#文件的替换并拷贝
f1=open("d:\\test.txt",'r')
f2=open("d:\\test2.txt",'w')
for s in f1.readlines():
    f2.write(s.replace('is','are'))
f1.close()
f2.close()